package main

import "fmt"

type Resulter interface {
	GetResult() int
	SetData(data ...interface{}) bool
}
type Object struct {
	numA int
	numB int
}
type Add struct {
	Object
}

func (a *Add) GetResult() int {
	return a.numA + a.numB
}
func (a *Add) SetData(data ...interface{}) bool {
	var b bool = true
	if len(data) > 2 {
		fmt.Println("参数个数错误")
	}
	value, ok := data[0].(int)
	if !ok {
		fmt.Println("第一个参数类型错误")
		b = false
	}
	value1, ok1 := data[1].(int)
	if !ok1 {
		fmt.Println("第二个参数类型错误")
		b = false
	}
	a.numA = value
	a.numB = value1
	return b
}

type sub struct {
	Object
}

func (s *sub) GetResult() int {
	return s.numA - s.numB
}
func (s *sub) SetData(data ...interface{}) bool {
	var b bool = true
	if len(data) > 2 {
		fmt.Println("参数个数错误")
	}
	value, ok := data[0].(int)
	if !ok {
		fmt.Println("第一个参数类型错误")
		b = false
	}
	value1, ok1 := data[1].(int)
	if !ok1 {
		fmt.Println("第二个参数类型错误")
		b = false
	}
	s.numA = value
	s.numB = value1
	return b
}

type OperatorFactory struct {
}

func (o *OperatorFactory) CreateOperator(op string) Resulter {
	switch op {
	case "+":
		add := new(Add)
		return add
	case "-":
		sub := new(sub)
		return sub
	default:
		return nil
	}
}
func OperatorWho(h Resulter) int {
	return h.GetResult()
}
func main() {
	var o OperatorFactory
	obj := o.CreateOperator("-")
	b := obj.SetData(30, 10)
	if b {
		num := OperatorWho(obj)
		fmt.Println(num)
	}
}
